<?php
namespace plugins\finance\controller;

use cmf\controller\PluginAdminBaseController;
use think\Db;
use think\Request;
use plugins\finance\model\FinanceModel;
use app\common\lib\model_operate\Transit;
use app\common\lib\file_operate\CsvOperate;
use plugins\finance\model\FinanceAccountsModel;
use app\common\lib\user_operate\ModuleOperate;

use plugins\pay\lib\Pay;
use plugins\pay\lib\Common as LCOM;

class AdminIndexController extends PluginAdminBaseController
{
	//我的账户
	public function index()
	{
		$param = $this->request->param();

		//权限检测 
		$check = ( new \plugins\store\Common )->getAllowAccess();
		if($check === true){
			//后台
			$where = ['finance_type'=>'store','finance_type_id'=>'admin'];
		}else{
			//店铺
			$where = ['finance_type'=>'store','finance_type_id'=>$check];
		}

		//账户信息
		$info = ( new FinanceModel )->where($where)->find();
		$this->assign('info',$info);

		//流水记录
		$search =  Transit::createTags('search');
		$search->setParam($param);
		$table = Transit::createTags('table');
		$table->setParam($search);	
		$pagesize = isset( $param [ 'pagesize' ] ) ? $param [ 'pagesize' ] : 20;

		$sear = [
		];

        //流水记录列表
		$list = $table->query()
		        ->order('id desc')
                ->paginates($pagesize,false,['query'=>$sear]);

		$this->assign('search',$search);
		$this->assign('table',$table);
		$this->assign('list',$list);

		return $this->fetch();
	}

	public function test()
	{

        $type = 'wechatpay' ; //wechatpay为微信支付方式标识
        $wechatpay= Pay::createInstance(  $type  );	//创建pay的class

        $bizcontent = [];


        // $bizcontent['out_trade_no'] = $result['message'];
        $bizcontent['out_trade_no'] = 'wegwqehowqjdasdmja';

        $money = 0.01;
        $bizcontent['body'] = '平台余额充值:'.$money;
        $bizcontent['total_fee'] = $money * 100;
        $bizcontent['trade_type'] = 'APP';	//交易类型

  		$bizcontent = json_encode($bizcontent);	

  		$res = $wechatpay->expense( $bizcontent ) ;	

  		dump($res);
  		exit();




        // $type = $this->recharge_aim ; 
        $type = 'wechatpay';
        $wechatpay= Pay::createInstance(  $type  );	//创建pay的class

        $bizcontent = [];
        //订单号
        $bizcontent['partner_trade_no'] = 'extract5fa4f220c0b55';
        //是否校验用户真实姓名
        $bizcontent['check_name'] = 'NO_CHECK';
        //金额
        $bizcontent['amount'] = 1;

        //备注
        $bizcontent['desc'] = '提现';

        //openid
        $bizcontent['openid'] = 'oRrdQt6W2e97o8FeXuF__GQFmG6E';

  		$bizcontent = json_encode($bizcontent);	

  		$res = $wechatpay->earning( $bizcontent );	

  		dump($res);	
	}

}